################################################################################
#
# libretro-beetle-pcfx
#
################################################################################
# Version: Commits on Oct 22, 2024
LIBRETRO_BEETLE_PCFX_VERSION = dd04cef9355286488a1d78ff18c4c848a1575540
LIBRETRO_BEETLE_PCFX_SITE = $(call github,libretro,beetle-pcfx-libretro,$(LIBRETRO_BEETLE_PCFX_VERSION))
LIBRETRO_BEETLE_PCFX_LICENSE = GPLv2
LIBRETRO_BEETLE_PCFX_DEPENDENCIES += retroarch

LIBRETRO_BEETLE_PCFX_PLATFORM = $(LIBRETRO_PLATFORM)

ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_S922X)$(BR2_PACKAGE_BATOCERA_TARGET_A3GEN2),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = CortexA73_G12B
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_RK3399),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = rpi4
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_BCM2711),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = rpi4
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_BCM2712),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = rpi5
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_S905)$(BR2_PACKAGE_BATOCERA_TARGET_S905GEN2),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = S905
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_RK3328),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = S905
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_S9GEN4),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = S905
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_H616)$(BR2_PACKAGE_BATOCERA_TARGET_H6)$(BR2_PACKAGE_BATOCERA_TARGET_H700),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = S905
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_RK3568)$(BR2_PACKAGE_BATOCERA_TARGET_S905GEN3),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = SM1
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_RK3588)$(BR2_PACKAGE_BATOCERA_TARGET_RK3588_SDIO)$(BR2_PACKAGE_BATOCERA_TARGET_T527),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = RK3588
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_S812),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = armv
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_ODIN),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = odin
else ifeq ($(BR2_PACKAGE_BATOCERA_TARGET_QCS6490)$(BR2_PACKAGE_BATOCERA_TARGET_SM8250)$(BR2_PACKAGE_BATOCERA_TARGET_SM8550),y)
LIBRETRO_BEETLE_PCFX_PLATFORM = sm8250
endif

define LIBRETRO_BEETLE_PCFX_BUILD_CMDS
	$(TARGET_CONFIGURE_OPTS) $(MAKE) CXX="$(TARGET_CXX)" CC="$(TARGET_CC)" \
	    -C $(@D) platform="$(LIBRETRO_BEETLE_PCFX_PLATFORM)" \
        GIT_VERSION="-$(shell echo $(LIBRETRO_BEETLE_PCFX_VERSION) | cut -c 1-7)"
endef

define LIBRETRO_BEETLE_PCFX_INSTALL_TARGET_CMDS
	$(INSTALL) -D $(@D)/mednafen_pcfx_libretro.so \
		$(TARGET_DIR)/usr/lib/libretro/pcfx_libretro.so
endef

$(eval $(generic-package))
